﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using PPAP.BO;
using PPAP.Model;

namespace PPAP.Web.Part
{
    public partial class SampleReportPrint : PageBase
    {
        PPARBO pbo = new PPARBO();
        SamplecardBO sbo = new SamplecardBO();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["rid"] != null)
                {
                    DataSet ds = pbo.GetReportByPPARid(Request.QueryString["rid"].ToString());
                    DataRow dr = ds.Tables[0].Rows[0];
                    //lblDecision.Text = dr["decisiontext"].ToString();
                    // lblExplanations.Text = dr["explanations"].ToString()==""?dr["remarks"].ToString():dr["explanations"].ToString();
                    lblQe.Text = dr["quanlityengineer"].ToString();
                    lblQM.Text = dr["quanlitymanager"].ToString();
                    lblQVP.Text = dr["quanlityvp"].ToString();
                    lblSamplingReportNo.Text = dr["samplingreportno"].ToString();
                    lblSupplier.Text = dr["suppliername"].ToString();

                    DataSet ds2 = sbo.GetList(" s.pparid=" + Request.QueryString["rid"].ToString() + " ");
                    foreach (DataRow drr in ds2.Tables[0].Rows)
                    {
                        if (drr["RESULT"].ToString() == "Y" || drr["RESULT"].ToString() == "R")
                        {
                            lblExplanations.Text += drr["testitemname"].ToString() + "\n" + drr["testitemname"].ToString() + " is not available for BDNT. Reason for deviation is " + drr["reason"].ToString() + "\n\n";
                        }
                    }

                    if (dr["finalresult"].ToString() == "G")
                    {
                        lblDecision.Text = "Successfully released ";
                    }
                    if (dr["finalresult"].ToString() == "Y")
                    {
                        lblDecision.Text = "The final result is conditionally released , the reason  is " + dr["reasondisapprovalbybp"].ToString();
                    }
                    if (dr["finalresult"].ToString() == "R")
                    {
                        lblDecision.Text = "We expect a new PPAR-Report as well as samples by the re-submission date " + (dr["resubmissiondate"].ToString() == "" ? "" : DateTime.Parse(dr["resubmissiondate"].ToString()).ToString("yyyy-MM-dd")) + ". ";
                    }
                }
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["rid"] != null)
            {
                PPAR p = pbo.GetModel(int.Parse(Request.QueryString["rid"].ToString()));
                if (p != null)
                {
                    p.EXPLANATIONS = lblExplanations.Text;
                    pbo.Update(p);
                }
            }
        }
    }
}